package com.sx.fams.task.biz.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.sx.fams.country.biz.ICountryBiz;
import com.sx.fams.country.entity.CountryTaskEntity;
import com.sx.fams.task.biz.ITaskBiz;
import com.sx.fams.task.dao.ITaskDao;
import com.sx.fams.task.entity.TaskEntity;

public class TaskBiz implements ITaskBiz {
	private ITaskDao taskdao;
	private ICountryBiz countrybiz;
	private Log log = LogFactory.getLog(this.getClass());
	
	/* (non-Javadoc)
	 * @see com.sx.fams.task.biz.ITaskBiz#queryTaskCounts(com.sx.fams.task.entity.TaskEntity)
	 */
	public String queryTaskCounts(TaskEntity task) {
		// TODO Auto-generated method stub
		String count = null;
		try {
			count = taskdao.queryTaskCounts(task);
		} catch (Exception e) {
			log.error("获取出访团组数量信息",e);
		}
		return count;
	}

	/* (non-Javadoc)
	 * @see com.sx.fams.task.biz.ITaskBiz#queryTaskInfos(com.sx.fams.task.entity.TaskEntity)
	 */
	public List<TaskEntity> queryTaskInfos(TaskEntity task) {
		// TODO Auto-generated method stub
		List<TaskEntity> list = null;
		try {
			list = taskdao.queryTaskInfos(task);
		} catch (Exception e) {
			log.error("获取出访团组信息",e);
		}
		return list;
	}

	/* (non-Javadoc)
	 * @see com.sx.fams.task.biz.ITaskBiz#addTaskInfo(com.sx.fams.task.entity.TaskEntity)
	 */
	public Integer addTaskInfo(TaskEntity task) {
		Integer taskid = null;
		try {
			taskid = taskdao.addTaskInfo(task);
			if(taskid!=null){
				Integer [] countryids = task.getCountryids();
				for (int i = 0; i < countryids.length; i++) {
					CountryTaskEntity cte = new CountryTaskEntity(taskid,countryids[i]);
					countrybiz.insertCountryTask(cte);
				}
			}
		} catch (Exception e) {
			log.error("新增团组出错请查明原因",e);
		}
		return taskid;
	}

	/**
	 * @return the taskdao
	 */
	public ITaskDao getTaskdao() {
		return taskdao;
	}

	/**
	 * @param taskdao the taskdao to set
	 */
	public void setTaskdao(ITaskDao taskdao) {
		this.taskdao = taskdao;
	}

	/**
	 * @return the countrybiz
	 */
	public ICountryBiz getCountrybiz() {
		return countrybiz;
	}

	/**
	 * @param countrybiz the countrybiz to set
	 */
	public void setCountrybiz(ICountryBiz countrybiz) {
		this.countrybiz = countrybiz;
	}
	
}
